package com.woniuxy.woniuticket.movieinfomodule.controller;

import com.woniuxy.woniuticket.movieinfomodule.dao.UsersInfoDAO;
import com.woniuxy.woniuticket.movieinfomodule.dto.Loginandinfoandvip;
import com.woniuxy.woniuticket.movieinfomodule.dto.UserandVip;
import com.woniuxy.woniuticket.movieinfomodule.service.impl.UserVipInfoServiceImp;
import com.woniuxy.woniuticket.pojo.UsersInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author zyf
 * @Description:TODO
 * @date 2019/6/19
 * @Version 1.0
 */
@Controller
@RequestMapping("/userinfo")
public class UserInfoController {
    @Autowired
    private UserVipInfoServiceImp userVipInfoServiceImp;
    @Autowired
    private UsersInfoDAO usersInfoDAO;
    @RequestMapping("/userinfo")
    @ResponseBody
    public Loginandinfoandvip getInfo(HttpSession session){
        System.out.println("获取个人信息");
        UsersInfo usersInfo = (UsersInfo) session.getAttribute("user");
        Loginandinfoandvip user = new Loginandinfoandvip();
        System.out.println(usersInfo);
        if(usersInfo != null){
            UserandVip userandVip =  userVipInfoServiceImp.queryUserInfo(usersInfo.getTelnumber());
            UsersInfo usersInfo1 = usersInfoDAO.queryIdByTel(usersInfo.getTelnumber());
            if(userandVip != null){
                user.setUserandVip(userandVip);
            }
            if(usersInfo1 != null){
                user.setUsersInfo(usersInfo1);
            }

            System.out.println(user);
            return user;
        }else{
            return null;
        }

    }

    @RequestMapping("/edit")
    @ResponseBody
    public String edit(String username,HttpSession session){

        UsersInfo usersInfo = (UsersInfo) session.getAttribute("user");
        usersInfo.setUsername(username);
        usersInfoDAO.updateUsername(usersInfo);
        return "success";
    }
}
